package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"mbti/model"
)

func LoginAdmin(ctx *gin.Context) {
	name := ctx.PostForm("adminName")
	password := ctx.PostForm("password")
	fmt.Println(name)
	id, _, _ := model.GetExistAdmin(name, password)
	if len(id) < 1 {
		ctx.JSON(422, gin.H{
			"code": 422,
			"msg":  "账号或密码错误",
		})
		return
	}

	ctx.JSON(200, gin.H{
		"code": 200,
		"msg":  "登陆成功",
	})
}

func LoginStudent(ctx *gin.Context) {
	class := ctx.PostForm("studentClass")
	specialize := ctx.PostForm("specialize")
	college := ctx.PostForm("college")
	name := ctx.PostForm("studentName")
	studentID := ctx.PostForm("studentID")

	fmt.Println(name)
	isOk := model.GetExistStudent(studentID, name, college, specialize, class)
	if isOk == false {
		ctx.JSON(422, gin.H{
			"code": 422,
			"msg":  "账号或密码错误",
		})
		return
	}

	ctx.JSON(200, gin.H{
		"code": 200,
		"msg":  "登陆成功",
	})
}
